﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WMS.API.Application.Command.BasicManagement.ProductManage;
using WMS.Domain.Entities.BasicManagement;
using WMS.ErrorCode;

namespace WMS.API.Controllers.BasicManagement
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductManageController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ProductManageController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 产品显示处理命令处理
        /// </summary>
        /// <param name="request">参训条件</param>
        /// <returns>返回产品管理列表</returns>
        [HttpGet]
        public Task<APIResult<APIPaging<ProductManageModel>>> ProductManageQuery([FromQuery] ProductManageCommand request)
        {
            var i = _mediator.Send(request);
            return i;
        }

        /// <summary>
        /// 添加产品管理命令处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddProductManage(AddProductManageCommand request)
        {
            var i = await _mediator.Send(request);
            return i;
        }
        /// <summary>
        /// 修改产品管理命令处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateProductManage(UpdateProductManageCommand request)
        {
            var i = await _mediator.Send(request);
            return i;
        }

        /// <summary>
        /// 产品删除命令处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<int>> DelProductManage([FromQuery]DelProductManageCommand request)
        {
            var i = await _mediator.Send(request);
            return i;
        }
    }
}
